package com.itheima.text2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPReceive {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(10002);

        while (true) {
            byte[] bytes = new byte[1024];

            DatagramPacket packet = new DatagramPacket(bytes,bytes.length);

            socket.receive(packet);

            int length = packet.getLength();

            String s = new String(bytes,0,length);

            System.out.println(s);
        }
    }
}
